#include "TaskQueue.hpp"
#include "MutexLock.hpp"
#include "Condition.hpp"

#include <iostream>

#include <queue>
using std::cout;
using std::endl;
using std::queue;

namespace wd{


TaskQueue::TaskQueue(int que_size)
:_que({1,2,3,4,5,6,7,8})
,_queSize(que_size)
,_mutex()
,_notFull(_mutex)
,_notEmpty(_mutex)
{
    
}

TaskQueue::~TaskQueue(){

}

bool TaskQueue::empty(){
    return _que.size() == 0;
}
bool TaskQueue::full(){
    return _que.size() == _queSize;
}
void TaskQueue::push(int val){
    _mutex.lock();
    
    while(full()){
       _notFull.wait(); 
    }
    _que.push(val);
    
    _notEmpty.notify_one();

    _mutex.unlock();
}


int TaskQueue::pop(){
    _mutex.lock();
    
    while(empty()){
        _notEmpty.wait();
    }
    int val = _que.front();
    _que.pop();

    _notFull.notify_one();
    _mutex.unlock();

    return val;

}


}
